$(document).ready(function() {
    $('#BlogRouter').keyup(function() {
        c_especial(this);
    });

    $('#BlogTitulo').change(function() {
        if ($.trim($('#BlogRouter').val()) == '') {
            $('#BlogRouter').val($(this).val());
            c_especial($('#BlogRouter'));
        }
    });
});
/**
 * Array de objectos de qual caracter deve substituir seu par com acentos
 */
var specialChars = [
    {val: "a", let: "áàãâä"},
    {val: "e", let: "éèêë"},
    {val: "i", let: "íìîï"},
    {val: "o", let: "óòõôö"},
    {val: "u", let: "úùûü"},
    {val: "c", let: "ç"},
    {val: "A", let: "ÁÀÃÂÄ"},
    {val: "E", let: "ÉÈÊË"},
    {val: "I", let: "ÍÌÎÏ"},
    {val: "O", let: "ÓÒÕÔÖ"},
    {val: "U", let: "ÚÙÛÜ"},
    {val: "C", let: "Ç"},
    {val: "", let: "?!()"}
];

/**
 * Função para substituir caractesres especiais.
 * @param {str} string
 * @return String
 */
function replaceSpecialChars(str) {
    var $spaceSymbol = '-';
    var regex;
    var returnString = str;
    for (var i = 0; i < specialChars.length; i++) {
        regex = new RegExp("[" + specialChars[i].let + "]", "g");
        returnString = returnString.replace(regex, specialChars[i].val);
        regex = null;
    }
    return returnString.replace(/\s/g, $spaceSymbol);
}
function c_especial(obj) {
    var $th = $(obj);
    $th.val(replaceSpecialChars($th.val()).replace(/[^a-zA-Z0-9-_]/g, '').toLowerCase());
}